package com.cn.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.utils.JsonMapper;


@WebServlet(value="/PageSizeServlet")
public class PageSizeServlet extends HttpServlet {
	/*@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("PageServletSize...");
		//接收请求
		int pageSize=2;
		int pageNow=1;
		String pageNowS=req.getParameter("pageNow");
		System.out.println("paegNows="+pageNowS);
		JsonMapper binder  = JsonMapper.nonDefaultMapper();
		//求出总页数
		int pageCount = (us.queryAllUsers().size() + pageSize - 1) / pageSize;
		req.setAttribute("pageCount", pageCount);
		
		if(pageNowS!=null) {
			//开始强转
			pageNow=Integer.valueOf(pageNowS);
			req.setAttribute("pageNow", pageNow);
			List<Users> list=us.queryUsersById(pageNow, pageSize);
			req.setAttribute("userList",list);
			//直接返回给JSON形式存入到Map集合中
			
			Map map=new HashMap();
			map.put("userList",list);
			map.put("success","aaabbbccc");
			String str=binder.toJson(map);
			resp.getWriter().println(str);
			//req.getRequestDispatcher("/pagesize.jsp").forward(req, resp);
			//System.out.println("str="+str);
		}else{//null
			List<Users> list2=us.queryAllUsers();
			req.setAttribute("userList",list2);
			req.setAttribute("pageSize",pageSize);//以下显示三条
			//返回给JSON形式返回给浏览器
			Map map2=new HashMap();
			map2.put("userList2",list2);
			map2.put("success2","aaabbbccc");
			String str2=binder.toJson(map2);
			System.out.println("str2="+str2);
			resp.getWriter().println(str2);
			//req.getRequestDispatcher("/pagesize.jsp").forward(req, resp);
		}
	}*/
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("sdfsdf");
		req.setAttribute("attr", "sdds");
		resp.getWriter().println("10");
		//resp.sendRedirect("amazon/index.jsp");
		//req.getRequestDispatcher("/index.jsp").forward(req, resp);
	}
}
